import cv2 as cv
import numpy as np

image = cv.imread("c5a134aaly1hmqiuhn0imj22p83lm7wo.jpg")

# 改变图像大小
resized_image = cv.resize(image, (400, 400))

# 调整图像亮度
brightened_image = cv.addWeighted(image, 1.2, np.zeros_like(image), 0, 0)

b, g, r = cv.split(brightened_image)  # 拆分亮度调整后的图像通道为b、g、r三个通道

cv.imshow("Resized Image", resized_image)
cv.imshow("Brightened Image - b", b)  # 显示b通道的亮度调整后的图像信息
cv.imshow("Brightened Image - g", g)  # 显示g通道的亮度调整后的图像信息
cv.imshow("Brightened Image - r", r)  # 显示r通道的亮度调整后的图像信息
cv.imshow("Original Image", image)  # 显示原始图像

cv.waitKey(0)
cv.destroyAllWindows()

pass

import cv2 as cv

image = cv.imread("gidle.jpg")

# 自定义通道拆分
height, width, _ = image.shape
top_half = image[:height//2, :]
bottom_half = image[height//2:, :]

# 对拆分的通道进行一些修改，例如调整亮度
top_half = cv.addWeighted(top_half, 1.2, np.zeros_like(top_half), 0, 0)
bottom_half = cv.addWeighted(bottom_half, 0.8, np.zeros_like(bottom_half), 0, 0)

# 合并修改后的通道
modified_image = np.vstack((top_half, bottom_half))

cv.imshow("Original Image", image)
cv.imshow("Modified Image", modified_image)
cv.waitKey(0)
cv.destroyAllWindows()


import cv2 as cv
import numpy as np
image = cv.imread("gidle.jpg")
# 最大像素值和最小像素值：您可以使用np.max()和np.min()函数来查看图像中最大和最小像素值。
print("Max pixel value:", np.max(image))
print("Min pixel value:", np.min(image))
print("image.shape",image.shape) # 输出图像的大小属性
print("image.size",image.size) # 输出图像的像素数目属性
print("image.dtype",image.dtype)
pass


import cv2 as cv
import numpy as np # 导入Numpy模块
imagegray = np.random.randint(0,256,size=[256,256],dtype=np.uint8) #生成一个随机灰#度图
cv.imshow("imagegray",imagegray)
cv.waitKey()
cv.destroyAllWindows()
pass


import cv2 as cv
import numpy as np

# 生成一个随机彩色图像
img = np.random.randint(0, 256, size=[256, 256, 3], dtype=np.uint8)

# 显示生成的随机彩色图像
cv.imshow("Random Color Image", img)
cv.waitKey(0)
cv.destroyAllWindows()
pass


import numpy as np

# 定义两个随机的4×4矩阵，范围在[0,255]之间
image1 = np.random.randint(0, 256, size=[4, 4], dtype=np.uint8)
image2 = np.random.randint(0, 256, size=[4, 4], dtype=np.uint8)

# 将两个矩阵相加，并确保结果在[0,255]之间
image3 = np.clip(image1.astype(int) + image2.astype(int), 0, 255).astype(np.uint8)

print("image1=\n", image1)
print("image2=\n", image2)
print("image3=\n", image3)
pass


import cv2 as cv
import numpy as np

# 读取图像
image = cv.imread("gidle.jpg")
cv.imshow("Original Image", image)

# 构造新的掩模图像
image_mask = np.zeros(image.shape, dtype=np.uint8)
image_mask[200:500, 200:500] = 255
cv.imshow("Mask Image", image_mask)

# 进行按位与操作，提取掩模内的图像
masked_image = cv.bitwise_and(image, image_mask)
cv.imshow("Masked Image", masked_image)

cv.waitKey(0)
cv.destroyAllWindows()
pass


import numpy as np# 定义两个随机的4×4矩阵，范围在[0,255]之间
image1 = np.random.randint(0,256,size=[4,4],dtype=np.uint8)
image2 = np.random.randint(0,256,size=[4,4],dtype=np.uint8)
print("image1=\n",image1)
print("image2=\n",image2)
print("image3=\n",image1- image2)
pass


import numpy as np
import cv2 as cv# 定义两个随机的4×4矩阵，范围在[0,255]之间
image1 = np.random.randint(0,256,size=[4,4],dtype=np.uint8)
image2 = np.random.randint(0,256,size=[4,4],dtype=np.uint8)
image3 = cv. subtract (image1,image2) # 使用cv2. subtract()函数实现图像的减法运算
print("image1=\n",image1)
print("image2=\n",image2)
print("image3=\n",image3)
pass


import numpy as np

# 定义一个随机的3×4矩阵，范围在[0,255]之间
array1 = np.random.randint(0, 256, size=[3, 4], dtype=np.uint8)

# 定义一个随机的4×3矩阵，范围在[0,255]之间
array2 = np.random.randint(0, 256, size=[4, 3], dtype=np.uint8)

# 将两个矩阵相乘
array3 = np.dot(array1, array2)

print("Array1=\n", array1)
print("Array2=\n", array2)
print("Array3=\n", array3)
